Skip to content

Conversation

Arrowana
Copy link

@Arrowana Arrowana commented Sep 2, 2025

Inspired by #100, roughly how i made it work in my fork

Note, there is the need to be able to set top_level_instruction_index on TransactionContext, otherwise the instruction in a batch are getting the wrong index, this is caused by the mollusk hack of not offering close to the original VM running and entire "transaction".

TransactionContext::push will set the instructions sysvar current index to top_level_instruction_index
https://github.com/anza-xyz/agave/blob/85d8b5859ebe462236fd22acdeaa556d82ad4f54/transaction-context/src/lib.rs#L446-L449

Copy link
Collaborator

@buffalojoec buffalojoec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think this mockup looks good to me. Then the new module is just the logic from #100?

@Arrowana Arrowana force-pushed the feat/instructions-sysvar branch from 0c3cb35 to 42a44b6 Compare September 2, 2025 13:50
@Arrowana
Copy link
Author

Arrowana commented Sep 2, 2025

Yeah I think this mockup looks good to me. Then the new module is just the logic from #100?

yes, i forced pushed since i forgot the file...

Since this is a sysvar though should this happen automagically inside mollusk setup? Rather than being an account people must add

@buffalojoec
Copy link
Collaborator

Since this is a sysvar though should this happen automagically inside mollusk setup? Rather than being an account people must add

Yep I think so! Typically I try to avoid overwriting user-provided accounts, even if it's a special account like this one. So we should make sure we first check if the account was provided already, and if it was not, then do this setup logic.

That being said, the harness does one allocation for the provided accounts slice when it creates a list of "transaction accounts" from the account compilation step.

mollusk/harness/src/lib.rs

Lines 683 to 687 in 1cfdd64

let CompiledAccounts {
program_id_index,
instruction_accounts,
transaction_accounts,
} = crate::compile_accounts::compile_accounts(instruction, accounts, loader_key);

So I'm thinking maybe we can push it into the accounts list here? This way it's in the transaction accounts list before we even create the TransactionContext and do the set_top_level_instruction_index step.

I'm open to whether or not we should include the auto-populated Instructions Sysvar account in the resulting accounts list. I can go either way: return it or cut it out.

@Arrowana
Copy link
Author

Arrowana commented Sep 3, 2025

Since this is a sysvar though should this happen automagically inside mollusk setup? Rather than being an account people must add

Yep I think so! Typically I try to avoid overwriting user-provided accounts, even if it's a special account like this one. So we should make sure we first check if the account was provided already, and if it was not, then do this setup logic.

That being said, the harness does one allocation for the provided accounts slice when it creates a list of "transaction accounts" from the account compilation step.

mollusk/harness/src/lib.rs

Lines 683 to 687 in 1cfdd64

let CompiledAccounts {
program_id_index,
instruction_accounts,
transaction_accounts,
} = crate::compile_accounts::compile_accounts(instruction, accounts, loader_key);

So I'm thinking maybe we can push it into the accounts list here? This way it's in the transaction accounts list before we even create the TransactionContext and do the set_top_level_instruction_index step.

I'm open to whether or not we should include the auto-populated Instructions Sysvar account in the resulting accounts list. I can go either way: return it or cut it out.

It can't be that deep because the process_instruction function only knows about the current instruction...

@buffalojoec
Copy link
Collaborator

It can't be that deep because the process_instruction function only knows about the current instruction...

Ah yes, you're right...

How about this? I set up a PR that should decouple things enough for you to stick this step right before the account compilation step and use a chained iterator to feed compile_accounts. We also need the index setting step as well, and I'll review the Agave PR asap.

#157

Let me know if this works for you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants